from PyQt5.QtWidgets import *
from status import Ui_Form
import sys

'''
if __name__ == '__main__':

    app = QApplication(sys.argv)
    mainWins = QMainWindow()
    ui = MainMenu.Ui_MainWindow()
    ui.setupUi(mainWins)
    mainWins.show()
    sys.exit(app.exec_())
'''

class Stats(QMainWindow):

    def __init__(self):
        super(Stats, self).__init__()
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        self.ui.retranslateUi(self)
        self.ui.Btn.clicked.connect(self.handleCalc)
        self.show()

    def handleCalc(self):

        info = self.ui.textEdit.toPlainText()
        print("----------")
        salary_above_20k = ''
        salary_below_20k = ''

        for line in info.splitlines():

            if not line.strip():
                continue
            parts = line.split(' ')

            parts = [p for p in parts if p]
            name, salary, age = parts
            if int(salary) >= 20000:
                salary_above_20k += name +"\n"
            else:
                salary_below_20k += name +"\n"

        QMessageBox.about(self, "统计结果", f'''薪资20k以上的有： \n{salary_above_20k}
                        \n 薪资20k以下的有： \n{salary_below_20k}''')

if __name__ == '__main__':

    app = QApplication(sys.argv)
    status = Stats()
    sys.exit(app.exec_())

# if __name__ == '__main__':
#
#     app = QApplication(sys.argv)
#     mainWins = QMainWindow()
#     ui = Ui_Form()
#     ui.setupUi(mainWins)
#     mainWins.show()
#     sys.exit(app.exec_())

